/*
 * control.h
 *
 *  Created on: Dec 4, 2023
 *      Author: boen
 */

#ifndef PERIPHERALS_INC_MOBILE_H_
#define PERIPHERALS_INC_MOBILE_H_

#include <mecanum_ik.h>
#include <mecanum_fk.h>
#include <nvic.h>

#define AXLE_SPACING  										0.18f 		// 轴距
#define WHEEL_SPACING										0.26f		// 轮距
#define WHEEL_RADIUS										0.04		// 轮半径

#if MOTOR_DC520
//pwm define	10.5KHZ
#define TIM_ARR 											14000u

#define PWM_MAX  											14000u
#define PWM_MIN												-14000u


#define PULSE2METER											0.0000635f  //0.0000625f	// 0.0000777f  // 脉冲数转换成米数对应转换系数

#define SPEED_MAX 											0.45825f	//m/s
#define SPEED_MIN											-0.45825f

#define MOBILE_AXIS_NULL									0u
#define MOBILE_AXIS_X										1u
#define MOBILE_AXIS_Y										2u
#define MOBILE_AXIS_R										3u

typedef struct
{
    TIM_HandleTypeDef* pEncoderTim;  						//编码器tim句柄

    TIM_HandleTypeDef* pPwmTimA;  							//PWM tim句柄1
    TIM_HandleTypeDef* pPwmTimB;  							//PWM tim句柄2

    uint32_t TIM_ChannelA;   								//pwm定时器通道1
    uint32_t TIM_ChannelB;   								//pwm定时器通道2
    uint8_t MotorId;

    PID_t PID;   											//速度PID控制
}motor_cfg_t;
#endif

#if MOTOR_STEP42

#define SPEED_MAX 											0.45825f	//m/s
#define SPEED_MIN											-0.45825f

#define MOBILE_AXIS_NULL									0u
#define MOBILE_AXIS_X										1u
#define MOBILE_AXIS_Y										2u
#define MOBILE_AXIS_R										3u

typedef struct
{
	uint8_t id;
	uint8_t state;
	uint8_t can_msg[8];

}motor_cfg_t;
#endif

void mobile_timer(void);

int mobile_move_x(float x);
int mobile_move_y(float y);
int mobile_rotation_z(float rad);
int mobile_is_ready(void);

void mobile_init(void);
void mobile_deinit(void);
void mobile_polling(void);

#endif /* PERIPHERALS_INC_MOBILE_H_ */
